Write a Rust program to determine if a given matrix is symmetric or not.
Write a Rust program to determine if a given matrix is symmetric or not.
263
22-Jun-2023
Aryan Kumar
23-Jun-2023Sure, here is a Rust program to determine if a given matrix is symmetric or not:
Rust
This program first defines a function called is_symmetric that takes a 4x4 matrix of i32 numbers as input and returns a bool value. The function iterates through the matrix, comparing each element to its corresponding element on the other side of the main diagonal. If any of the elements are not equal, then the function returns false. Otherwise, the function returns true.
The main function of the program then calls the is_symmetric function with the matrix [[1, 2, 3, 4], [2, 5, 6, 7], [3, 6, 9, 8], [4, 7, 8, 10]] as input. The result of the function call is then printed to the console.
To run the program, you can save it as a file called is_symmetric.rs and then compile it using the following command:
Code snippet
Once the program is compiled, you can run it using the following command:
Code snippet
This will print the following output to the console:
Code snippet